package com.acane.instagram.core.model.network.retrofit

import com.acane.instagram.core.model.Notification
import com.acane.instagram.core.model.PostInfo
import com.acane.instagram.core.model.Tag
import com.acane.instagram.core.model.UserInfo
import com.acane.instagram.core.model.dto.CommentDTO
import com.acane.instagram.core.model.dto.CommentLikeDTO
import com.acane.instagram.core.model.dto.FollowDTO
import com.acane.instagram.core.model.dto.LikeDTO
import com.acane.instagram.core.model.request.SensitiveCheckRequest
import com.acane.instagram.core.model.response.NetworkResponse
import com.acane.instagram.feature.login.LoginResponse
import okhttp3.MultipartBody
import okhttp3.RequestBody
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.Multipart
import retrofit2.http.POST
import retrofit2.http.Part
import retrofit2.http.Path
import retrofit2.http.Query

// 网络请求接口
interface MyNetworkApiService {
    // 获取推荐用户列表
    @GET("user/recommend/{userId}")
    suspend fun getRecommendUserList(
        @Path(value = "userId") userId: String,
        ): NetworkResponse<List<UserInfo>>

    @GET("user/{userId}/avatar")
    suspend fun getUserAvatar(
        @Path("userId") userId: String
    ): NetworkResponse<String>

    @GET("post/recommend/list")
    suspend fun getRecommendPostList(
        @Query(value = "userId") userId: String,
    ): NetworkResponse<List<PostInfo>>

    @POST("login")
    suspend fun login(
        @Query(value = "userName") userName: String?,
        @Query(value = "password") password: String?
    ): LoginResponse

    @GET("post/get/{userId}")
    suspend fun getPostListById(
        @Path("userId") userId: String,
    ): NetworkResponse<List<PostInfo>>

    @GET("user/get/{userId}")
    suspend fun getUserById(
        @Path("userId") userId: String,
    ): NetworkResponse<UserInfo>

    @GET("user/judge/followed")
    suspend fun judgeIsFollowed(
        @Query("followingId") followingId: String,
        @Query("followerId") followerId: String?
    ): NetworkResponse<Boolean>

    @GET("chat/history")
    suspend fun getChatHistory(
        @Query("sender") sender: String,
        @Query("receiver") receiver: String
    ): NetworkResponse<List<Notification.ChatMessage>>

    @GET("user/message/list")
    suspend fun getFriendMessageList(
        @Query("userName") userName: String?
    ): NetworkResponse<List<UserInfo>>

    @GET("user/get/userName")
    suspend fun getUserByUserName(
        @Query("userName") chatName: String)
            : NetworkResponse<UserInfo>

    @Multipart
    @POST("api/upload/media")
    suspend fun uploadMedia(
        @Part file: MultipartBody.Part
    ): NetworkResponse<String>

    @POST("post/add")
    suspend fun createNewPost(
        @Body postInfo: PostInfo
    ): NetworkResponse<PostInfo>

    @GET("post/position")
    suspend fun getPostPosition(
        @Query("postId") postId: String,
        @Query("userId") userId: String
    ) : NetworkResponse<Int>

    @GET("comment/history")
    suspend fun getCommentHistory(
        @Query("userId") userId: String
    ) : NetworkResponse<List<CommentDTO>>

    @GET("like/history")
    suspend fun getLikeHistory(
        @Query("userId") userId: String
    ) : NetworkResponse<List<LikeDTO>>

    @GET("follow/history")
    suspend fun getFollowHistory(
        @Query("userId") userId: String
    ) : NetworkResponse<List<FollowDTO>>

    @GET("post/get/one")
    suspend fun getPostById(
        @Query("postId") postId: String
    ): NetworkResponse<PostInfo>

    @GET("comment/list")
    suspend fun getCommentListByPostId(
        @Query("postId") postId: String
    ): NetworkResponse<List<CommentDTO>>

    @POST("comment/add")
    suspend fun createNewComment(
        @Body commentDTO: CommentDTO
    ) : NetworkResponse<CommentDTO>

    @POST("post/like")
    suspend fun likePost(
        @Query ("postId") postId: String,
    ): NetworkResponse<Int>

    @POST("post/unlike")
    suspend fun unlikePost(
        @Query ("postId") postId: String,
    ): NetworkResponse<Int>

    @POST("comment/like")
    suspend fun likeComment(
        @Query ("commentId") commentId: String,
    ): NetworkResponse<Int>

    @POST("comment/unlike")
    suspend fun unLikeComment(
        @Query ("commentId") commentId: String,
    ): NetworkResponse<Int>

    @GET("like/isLike")
    suspend fun judgeIsLiked(
        @Query("postId") postId: String,
        @Query("likerId") likerId: String?
    ): NetworkResponse<Boolean>

    @POST("follow")
    suspend fun sendFollowRequest(
        @Query("followingId") followingId: String,
        @Query("followerId") followerId: String?
    ): NetworkResponse<FollowDTO>

    @POST("follow/unFollow")
    suspend fun sendUnFollowRequest(
        @Query("followingId") followingId: String,
        @Query("followerId") followerId: String?
    ): NetworkResponse<FollowDTO>

    @GET("comment/get/one")
    suspend fun getCommentById(
        @Query("commentId") commentId: String
    ): NetworkResponse<CommentDTO>

    @GET("comment/like/history")
    suspend fun getCommentLikeHistory(
        @Query("userId") userId: String
    ) : NetworkResponse<List<CommentLikeDTO>>

    @GET("comment/isLike")
    suspend fun judgeIsCommentLiked(
        @Query("commentId") commentId: String?,
        @Query("likerId") likerId: String?
    ): NetworkResponse<Boolean>

    @GET("follow/following/list")
    suspend fun getFollowingList(
        @Query("userId") userId: String
    ): NetworkResponse<List<UserInfo>>

    @GET("follow/follower/list")
    suspend fun getFollowerList(
        @Query("userId") userId: String
    ): NetworkResponse<List<UserInfo>>

    @GET("post/recommend/video")
    suspend fun getRecommendVideoList(
        @Query("userId") userId: String
    ): NetworkResponse<List<PostInfo>>

    @GET("user/search")
    suspend fun userSearchResults(
        @Query("keyword") query: String
    ): NetworkResponse<List<UserInfo>>

    @GET("post/search")
    suspend fun postSearchResults(
        @Query("keyword") query: String
    ): NetworkResponse<List<PostInfo>>

    @GET("tag/get/list")
    suspend fun getTagList(
    ): NetworkResponse<List<Tag>>

    @Multipart
    @POST("api/upload/avatar")
    suspend fun uploadAvatar(
        @Part("userId") userId: RequestBody,
        @Part file: MultipartBody.Part
    ): NetworkResponse<String>

    @POST("user/update")
    suspend fun updateUserInfo(
        @Body userInfo: UserInfo
    ): NetworkResponse<UserInfo>

    @POST("user/register")
    suspend fun register(
        @Body userInfo: UserInfo,
    ): NetworkResponse<UserInfo>

    @GET("collection/get/list")
    suspend fun getCollectionPostList(
        @Query("userId") userId: String
    ): NetworkResponse<List<PostInfo>>

    @GET("collection/judge/collected")
    suspend fun judgeIsCollected(
        @Query("postId") postId: String,
        @Query("userId") userId: String?
    ): NetworkResponse<Boolean>

    @POST("collection/add")
    suspend fun collectPost(
        @Query("postId") postId: String,
        @Query("userId") userId: String?
    ): NetworkResponse<Boolean>

    @POST("collection/cancel")
    suspend fun unCollectPost(
        @Query("postId") postId: String,
        @Query("userId") userId: String?
    ): NetworkResponse<Int>

    @POST("sensitive/check")
    suspend fun checkSensitive(
        @Body request: SensitiveCheckRequest
    ): NetworkResponse<Boolean>

}